
//泛型：就是适用于许多类型

//泛型的上界


class Alg3 {
    //不依赖于当前对象
    public static <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}

class Alg2 {
    public<E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}

class Alg<E extends Comparable<E>> {
    public E findMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Test {

    public static void main(String[] args) {
        Integer[] array = {1,3,4,6,3,6};
        Integer val = Alg3.findMax(array);
        System.out.println(val);
    }

    public static void main2(String[] args) {
        Alg2 alg2 = new Alg2();
        Integer[] array = {1,3,4,6,3,6};
        Integer val = alg2.<Integer>findMax(array);
        System.out.println(val);
    }

    public static void main1(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {1,3,4,6,3,6};
        Integer val = alg.findMax(array);
        System.out.println(val);

    }
}
